//
// Created by xili on 2024/8/21 20:02.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int wateringPlants(vector<int> &plants, int capacity) {
        int n = plants.size();
        int cur = capacity;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (cur >= plants[i]) {
                ans++;
                cur -= plants[i];
            } else {
                ans += 2 * i + 1;
                cur = capacity - plants[i];
            }
        }
        return ans;
    }
};